//
//  PhotosetAddViewController.m
//  iFlickr
//
//  Created by 张 霄鹤 on 09-7-28.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "PhotosetAddViewController.h"

#import "DataManager.h"


@implementation PhotosetAddViewController

@synthesize photoID;

/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	[self.navigationItem setRightBarButtonItem:btnSubmit];
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}




#pragma mark Table view methods

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
	NSInteger ret = 0;
	switch (section) {
		case 0:
			ret = 2; // TODO 标题，描述
			break;
		case 1:
			ret = 1; // TODO 图片部分
			break;

	}
    return ret;
}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
//		// 针对不同的目标平台进行适配
//#ifndef __IPHONE_3_0
//		cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
//#else
//        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
//#endif
		// 装载 nib中的Cell
		
		NSInteger section = indexPath.section;
		NSInteger row = indexPath.row;
		
		if(section == 0){
			switch (row) {
				case 0:
					cell = cellTitle;
					break;
				case 1:
					cell = cellDesc;
					break;
				default:
					break;
			}
		}else if(section == 1){
			if(row == 0 ){
				cell = cellPhoto;
				cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
			}
		}		
    }
    
	// Configure the cell.
	
	
	return cell;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
	NSString *ret = nil;
	switch (section) {
		case 0:
			ret = [NSString stringWithString:(NSLocalizedStringFromTable(@"SOFT_INFO",@"main",@""))];
			break;
		case 1:
			ret = [NSString stringWithString:(NSLocalizedStringFromTable(@"PRIMARY_PHOTO",@"main",@""))];
			break;
			
		default:
			break;
	}
	return ret;
}


// Override to support row selection in the table view.
/**
 * 执行相应操作
 */
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
	
    // Navigation logic may go here -- for example, create and push another view controller.
	// AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil];
	// [self.navigationController pushViewController:anotherViewController animated:YES];
	// [anotherViewController release];
	NSInteger section = indexPath.section;
	[tableView deselectRowAtIndexPath:indexPath animated:NO];
	if(section == 1){
		// TODO 进入到flickr.photos.getNotInSet 并且显示图片列表
		DataManager *dm = [DataManager sharedDataManager];
		[dm getNotInSets];
	}	
}

#pragma mark -
#pragma mark UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
	return [textField resignFirstResponder];
}

#pragma mark -
#pragma mark Photoset Submit

-(IBAction)submitAction:(id)sender{
	NSString *title = txtTitle.text;
	NSString *desc = txtDescription.text;
	if(title){
		if(desc == nil){
			desc = @"photoset";
		}
		NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:title,@"title",desc,@"description",self.photoID,@"primary_photo_id ",nil];
		[self submitPhotoset:params];
	}
}

/**
 * 提交添加照片集的操作
 * @param params 照片集参数，title,description,primary_photo_id
 */
-(void)submitPhotoset:(NSDictionary *)params{
	
}



- (void)dealloc {
    [super dealloc];
}


@end
